package org.soc.timesheet.server.domain.service;

import java.util.List;

import org.soc.timesheet.custom.domain.filters.RolesFilter;
import org.soc.timesheet.domain.Roles;
import org.soc.timesheet.domain.repository.RolesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class RolesServiceImpl implements RolesService {

	@Autowired
    RolesRepository rolesRepository;

	public long countAllRoleses() {
        return rolesRepository.count();
    }

	public void deleteRoles(Roles roles) {
        rolesRepository.delete(roles);
    }

	public Roles findRoles(Integer id) {
        return rolesRepository.findOne(id);
    }

	public List<Roles> findAllRoleses() {
        return rolesRepository.findAll();
    }

	public List<Roles> findRolesEntries(int firstResult, int maxResults) {
        return rolesRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveRoles(Roles roles) {
        rolesRepository.save(roles);
    }

	public Roles updateRoles(Roles roles) {
        return rolesRepository.save(roles);
    }

	@Override
	public Page<Roles> findAll(PageRequest pageRequest) {
		// TODO Auto-generated method stub
		return rolesRepository.findAll(pageRequest);
	}

	@Override
	public Page<Roles> findByFilters(RolesFilter filter, PageRequest pageRequest) {
		// TODO Auto-generated method stub
		return rolesRepository.findAll(filter, pageRequest);
	}
}
